#!/usr/bin/perl -w
use strict;
use MediaWiki::API;
my $args = @ARGV;
my $text;
if ( $args == 1 ) {
	$text = <STDIN>;
} elsif ( $args == 2 ) {
	$text = $ARGV[1];
} else { 
	print "\tUsage: ./writePage <title> <content>\n";
	print "\t\tExample: echo \"test submission\" | ./writePage \"Main Page\"\n";
	print "\t\tExample: ./writePage \"Main Page\" (This example will let you type a line as input)\n";
	print "\t\tExample: ./writePage \"Main Page\" < input.txt\n";
	print "\t\tExample: ./writePage \"Main Page\" \"Test Submission\"\n";
	exit;
}
my $api = MediaWiki::API->silent();
my $page = new MediaWiki::Page($ARGV[0]);
$page->{text} = $text;
my $success = $page->save($api);
if ( $success ) {
	print "Successfully wrote page.\n";
} else {
	print "Could not write page.\n"
}
